package cn.tedu.adminsystem.webapi.controller;

import cn.tedu.adminsystem.service.IRoleService;
import cn.tedu.community.commons.pojo.admRole.vo.RoleListItemVO;
import cn.tedu.community.commons.pojo.notice.vo.UserNoticeListItemVO;
import cn.tedu.community.commons.pojo.user.vo.UserListVO;
import cn.tedu.community.commons.restful.JsonPage;
import cn.tedu.community.commons.restful.JsonResult;
import cn.tedu.epidemic.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Pattern;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "用户控制器")
@Validated
@RequestMapping("/user")
public class UserController {

    @DubboReference
    private UserService dubboUserService;

    @ApiOperation("展示返乡人员列表")
    @GetMapping("/{page:[0-9]+}/{pageSize:[0-9]+}/isReturnPeopleList")
    public JsonResult<JsonPage<UserListVO>> isReturnPeopleList(@PathVariable Integer page,
                                                               @PathVariable Integer pageSize) {
        log.debug("展示返乡人员列表，页码是：{}，每页条数是：{}", page, pageSize);
        JsonPage<UserListVO> returnPeopleList = dubboUserService.isReturnPeopleList(page, pageSize);
        log.debug("展示返乡人员列表的数据是：{}", returnPeopleList);
        return JsonResult.ok(returnPeopleList);
    }

    @ApiOperation("展示非返乡人员列表")
    @GetMapping("/{page:[0-9]+}/{pageSize:[0-9]+}/NotReturnPeopleList")
    public JsonResult<JsonPage<UserListVO>> NotReturnPeopleList(@PathVariable Integer page,
                                                                @PathVariable Integer pageSize) {
        log.debug("展示非返乡人员列表，页码是：{}，每页条数是：{}", page, pageSize);
        JsonPage<UserListVO> notReturnPeopleList = dubboUserService.NotReturnPeopleList(page, pageSize);
        log.debug("展示非返乡人员列表的数据是：{}", notReturnPeopleList);
        return JsonResult.ok(notReturnPeopleList);
    }

    @ApiOperation("查询用户名或姓名展示列表")
    @GetMapping("/{page:[0-9]+}/{pageSize:[0-9]+}/username={username}/byUsernameList")
    public JsonResult<JsonPage<UserListVO>> ListByUsernameOrName(@Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9]{1,10}+$",
            message = "请输入1-10位中文、英文、数字但不包括下划线等符号的用户名或姓名！") @PathVariable String username,
                                                                 @PathVariable Integer page,
                                                                 @PathVariable Integer pageSize) {
        log.debug("查询用户名或姓名展示列表，页码是：{}，每页条数是：{},姓名或用户名是：{}", page, pageSize,username);
        JsonPage<UserListVO> userListVOJsonPage = dubboUserService.ListByUsernameOrName(page, pageSize, username);
        log.debug("查询用户名或姓名展示列表的数据是：{}", userListVOJsonPage);
        return JsonResult.ok(userListVOJsonPage);
    }
}
